package com.kilim.idea;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.strands.Strand;
import org.springframework.util.StopWatch;

import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;

/**
 * @projectName: learn_used_code
 * @packageName: com.kilim.idea
 * @className: com.kilim.idea-> TestQuasar
 * @createDate: 2021-12-15 17:11
 * @author: ZhangSheng
 * @version: 1.0
 * @description:
 */
public class TestQuasar {


    public static void main(String[] args) throws Exception{
        CountDownLatch count  = new CountDownLatch(100000);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        IntStream.range(0,100000).forEach(i-> new Fiber() {
            @Override
            protected String run() throws SuspendExecution, InterruptedException {
                Strand.sleep(1000 );
                count.countDown();
                return  "aa-bb";
            }
        }.start());
        count.await();
        stopWatch.stop();
        System.out.println("结束了: " + stopWatch.prettyPrint());
    }
//    2526396900    2775602300      3679256000
//    7283512200    14918038400     22699677800
//                                  23948197700

}
